<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>表格</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
			<link rel="stylesheet" type="text/css" href="styles.css">
		-->
		<jsp:include page="../basic/easyui_loder.jsp" flush="true"/>
		
		<script type="text/javascript">
			$(document).ready(function(){
				
				/**
				 * 获得选择的行的id
				 */
				var getSelectIds = function(){
					//{"contentidList[1]":1111111,},{},{},]
					var selectRows = $('#tt').datagrid('getSelections');
					
					var jsonData = "{";
					
					for(var i =0;i<selectRows.length;i++){
						if(i != 0){
							jsonData = jsonData + ",";
						}
						jsonData = jsonData + "\"contentidList[" + i + "]\":" + selectRows[i].listprice;
					}
					jsonData = jsonData + "}";
					
					return jsonData;
				}
				
				
				/** 删除 **/
				var deleteRow = function(){
					var selectRows = $('#tt').datagrid('getSelections');
					if(selectRows.length == 0){
						$.messager.alert('警告','请选择要删除的行！');
					}else{
						var contentid = selectRows[0].itemid;
						
						var jsonData = jQuery.parseJSON(getSelectIds());
						
						console.log(jsonData);
						
						$.ajax({
							type : "POST",
							dataType : "json",
							url : "testAction_deleteTest",
							data: jsonData,
							success : function(data){
								alert("success...");
							},
							error : function(XMLHttpRequest, textStatus,errorThrown){
								
							}
						});
					}
				}
				
				$('#tt').datagrid({
					title:'测试表格',
					iconCls:'icon-save',
					width: 900,
					striped: true,//斑马线
					height: 500,
					rownumbers: true,
					singleSelect: false,//是否单选
					url: 'testAction_getItems',
					pagination: true, //分页
					columns:[[
						{field: 'ck',checkbox:true},
						{field: 'itemid',title:'ItemID',width:80,sortable:true},
						{field: 'productid',title:'ProductID',width:80,sortable:true,editor:"text"},
						{field: 'listprice',title:'ListPrice',width:80,align:'right',sortable:true},
						{field: 'unitcost',title:'UnitCost',width:80,align:'right',sortable:true},
						{field: 'attr1',title:'Attribute',width:100,sortable:true},
						{field: 'status',title:'Status',width:60},
						{field: 'opt',title:'Operation',width:150,align:'center',
							formatter:function(value,rec){
								var editBtn = "<a id='editBtn' href='javaScript:void(0)'>修改</a>";
								
								var deleteBtn = "<a id='deleteBtn' href='javaScript:void(0)'>删除</a>";
								
								return (editBtn + "&nbsp;&nbsp;" + deleteBtn);
							}
						}
					]],
					toolbar:[{
						text:'添加',
						iconCls:'icon-add',
						handler:function(){
							alert('add');
						}
					},{
						text:'修改',
						iconCls:'icon-edit',
						handler:function(){
							alert('edit');
						}
					},{
						text:'删除',
						iconCls:'icon-cancel',
						handler:function(){
							deleteRow();
						}
					},{
						text:'添加列',
						iconCls:'icon-cancel',
						handler:function(){
							alert('add');
						}
					}]
				});
			});
		</script>

	</head>

	<body>
		<hr />
		<h2>表格</h2>
		<table id="tt1" align="center" border="1px">
			<tr>
				<td>11</td>
				<td>22</td>
			</tr>
		</table>
		
		<div id="tt" align="center"></div>
		
		<br/><br/>

	</body>
</html>
